package com.haieros.www.purerunshowsystem.utils;

import android.content.Context;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 时间判断工具类
 * Created by Administrator on 2017\12\24
 */

public class DateJudgeUtil {
    public static DateJudgeUtil mDateJudgeUtil;
    Date beginTime = null;
    Date endTime = null;
    Date nowTime = null;
    Date beginTime1 = null;
    Date endTime1 = null;
    Date beginTime2 = null;
    Date endTime2 = null;
    Date mainBeginTime;
    Date mainEndTime;
    SimpleDateFormat df;
    int flag = 1;
    private  Context mContext;
    private DateJudgeUtil(Context context) {
        mContext=context;
        initTimeRange();
    }

    public static DateJudgeUtil getInstence(Context context) {
        if (mDateJudgeUtil == null) {
            synchronized (DateJudgeUtil.class) {
                if (mDateJudgeUtil == null) {

                    mDateJudgeUtil = new DateJudgeUtil(context);
                }
            }
        }
        return mDateJudgeUtil;
    }

    //初始时间段值
    private void initTimeRange() {
        df = new SimpleDateFormat("HH:mm:ss");//设置日期格式
        try {
            beginTime = df.parse("17:32:00");
            endTime = df.parse("17:35:00");
            beginTime1 = df.parse("10:00:00");
            endTime1 = df.parse("23:45:00");
            beginTime2 = df.parse("17:45:00");
            endTime2 = df.parse("17:55:00");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int judgeTime(Date nowDate) {
        try {
            nowTime = df.parse(df.format(nowDate));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);
        Calendar begin = Calendar.getInstance();
        begin.setTime(beginTime);
        Calendar end = Calendar.getInstance();
        end.setTime(endTime);
        Calendar begin1 = Calendar.getInstance();
        begin1.setTime(beginTime1);
        Calendar end1 = Calendar.getInstance();
        end1.setTime(endTime1);
        Calendar begin2 = Calendar.getInstance();
        begin2.setTime(beginTime2);
        Calendar end2 = Calendar.getInstance();
        end2.setTime(endTime2);
        if (date.after(begin) && date.before(end)) {

            return 1;
        } else if(date.after(begin1) && date.before(end1))
        {
            return 2;
        }
        else if(date.after(begin2) && date.before(end2))
        {
            return 3;
        }
        return 503;
    }
    public boolean judgeTimeTwo(Date nowDate) {

        try {
            nowTime = df.parse(df.format(nowDate));
           mainBeginTime = df.parse("10:10:00");
           mainEndTime = df.parse("20:30:00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar dateMain = Calendar.getInstance();
        dateMain.setTime(nowTime);
        Calendar mainBegin = Calendar.getInstance();
        mainBegin.setTime(mainBeginTime);
        Calendar mainEnd = Calendar.getInstance();
        mainEnd.setTime(mainEndTime);
        if (dateMain.after(mainBegin) && dateMain.before(mainEnd)) {
        return true;
        }
        return false;
    }
}
